#!/bin/bash

# 升级系统并安装必要的依赖
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common  -y

# 添加Docker的GPG密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# 再次更新APT包索引
sudo apt-get update

# 安装最新版本的Docker
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
sudo docker run hello-world
sudo systemctl enable docker 
sudo groupadd docker
sudo usermod -aG docker $USER


# 安装Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo docker-compose --version

echo "重启docker生效"

# 询问用户是否希望立即重启电脑  
read -p "是否立即重启电脑？ (Y/N): " answer  
  
# 检查用户的输入，并相应地执行操作  
case $answer in  
    [Yy]* )  
        echo "正在重启电脑..."  
        sudo reboot 
        ;;  
    * )  
        echo "未执行重启操作。"  
        ;;  
esac


#sudo curl -fsSL https://gitee.com/tech-shrimp/docker_installer/releases/download/latest/linux.sh| bash -s docker --mirror Aliyun
